/*
 * Copyright (c) 2011. This file is public under GPLv3 license.
 * For more information about license please refer to http://www.gnu.org/licenses/gpl.html
 */

package com.freetools.watchdog;

import com.freetools.watchdog.engine.CommandFlow;
import com.freetools.watchdog.engine.CommandParser;
import com.freetools.watchdog.exceptions.CommandErrorException;
import com.freetools.watchdog.exceptions.ParametersErrorException;
import com.freetools.watchdog.model.IModelHolder;
import com.freetools.watchdog.model.ModelHolder;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Bootstrap class for console using of application
 * Date: Jun 23, 2010
 *
 * @author Michael Morozov
 */
public class Console
{
    public static void main(String[] args) throws IOException, CommandErrorException, ParametersErrorException
    {
        StringBuilder initialCommandLine = new StringBuilder();
        for (String arg : args)
        {
            initialCommandLine.append(arg).append(" ");
        }

        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String commandLine = initialCommandLine.toString();
        IModelHolder model = new ModelHolder();
        while (true)
        {
            CommandParser.parseCommandLineAndFillModel(commandLine, model);
            if (CommandFlow.execute(model)) break;
            commandLine = reader.readLine();

        }
    }
}
